//
//  JCTabBar.swift
//  swiftWeibo
//
//  Created by mac on 15/12/15.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class JCTabBar: UITabBar {

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {

        super.init(frame: frame)
        // 初始化
        tintColor = UIColor.orangeColor()
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        var index = 0
        let width = bounds.size.width / 5
        // 创建frame
        let frame = CGRect(x: 0, y: 0, width: width, height: bounds.size.height)
        
        for view in subviews{
        
            if view.isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
                
                index += index == 1 ? 2 : 1
            }
        }
    }
    
}


